package com.yxw.zookeeper.client;

/**
 * Created by hp on 2016/1/22.
 */
public class SushuTest {
    /**
     * 　　* 打印自然数n以内的素数
     * <p/>
     *
     */
    public static void printPrime(int n) {

        //是否为质数

        boolean isPrime;

        for (int i = 1; i <= n; i++) {

            isPrime = true;

            for (int j = 2; j < i; j++) {

                //若能除尽，则不为质数

                if ((i % j) == 0) {

                    isPrime = false;

                    break;

                }

            }

            //如果是质数，则打印

            if (isPrime) {

                System.out.println(i);

            }

        }

    }

    public  static boolean isPrime(long n) {
        if (n <= 3) {
            return n > 1;
        }
        if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }

        for (int i = 5; i * i <= n; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Long n = 9223372036854775807L;
        for (int i = 0;i < n;i++){
            if(isPrime(i)){
                System.out.println(i);
            }
        }
    }
}
